package stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectStreamEx {
	String filename = "Data.dat";
	
	public ObjectStreamEx(){
		save();
		load();
	}
	
	public void save(){ // Object 타입으로 저장
		Score s = new Score("Jint","Kim",100,100);
		
		try{
			File f = new File(filename);
			FileOutputStream fos = new FileOutputStream(f);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(s);
			oos.close();
			fos.close();
		}catch(Exception ex){
			
		}
		
	}
	
	public void load(){
		try{
			File f = new File(filename);
			FileInputStream fis = new FileInputStream(f);
			ObjectInputStream ois = new ObjectInputStream(fis);
			Score o = (Score)ois.readObject();
			System.out.println("Id : " + o.getUserId());
			System.out.println("Name : " + o.getIrum());
			System.out.println("Kor : " + o.getKor());
			System.out.println("Eng : " + o.getEng());
			System.out.println("Total : " + o.getTot());
			ois.close();
			fis.close();
			
		}catch(Exception ex){
			
		}
	}
	
	public static void main(String[] args) {
		ObjectStreamEx ose = new ObjectStreamEx();

	}

}
